package ceha.application;

import javax.swing.JInternalFrame;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

public class CEHAData extends javax.swing.JFrame   {

    private CEHAFiche fiche;

    public CEHAData() {
        initComponents();
       

    }

    public CEHAData(CEHAFiche fiche) {
        this.fiche = fiche;
        initComponents();
    }

    public JTable getMasterTable() {
        return masterTable;
    }

    public JInternalFrame getDonneesTablesJIF() {
        return donneesTablesJIF;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("BDDCEHAPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT f FROM Fiche f");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        desktop = new javax.swing.JDesktopPane();
        donneesTablesJIF = new javax.swing.JInternalFrame();
        masterscrollpane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        auteurC = new javax.swing.JCheckBox();
        raz = new javax.swing.JButton();
        idC = new javax.swing.JCheckBox();
        sourceC = new javax.swing.JCheckBox();
        typedocC = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        donneesTablesJIF.setBackground(new java.awt.Color(204, 255, 204));
        donneesTablesJIF.setIconifiable(true);
        donneesTablesJIF.setResizable(true);
        donneesTablesJIF.setTitle("DONNEES CEHA");
        donneesTablesJIF.setOpaque(true);
        donneesTablesJIF.setVisible(true);

        masterscrollpane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        masterscrollpane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        masterTable.setGridColor(new java.awt.Color(0, 0, 0));

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${source}"));
        columnBinding.setColumnName("Source");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${typedocument}"));
        columnBinding.setColumnName("Typedocument");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${auteur}"));
        columnBinding.setColumnName("Auteur");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${titre}"));
        columnBinding.setColumnName("Titre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${date}"));
        columnBinding.setColumnName("Date");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${datecorrection}"));
        columnBinding.setColumnName("Datecorrection");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${datedonation}"));
        columnBinding.setColumnName("Datedonation");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${datetexte}"));
        columnBinding.setColumnName("Datetexte");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dimension}"));
        columnBinding.setColumnName("Dimension");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${droitsrepro}"));
        columnBinding.setColumnName("Droitsrepro");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fond}"));
        columnBinding.setColumnName("Fond");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idcorrecteur}"));
        columnBinding.setColumnName("Idcorrecteur");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${imagefilename}"));
        columnBinding.setColumnName("Imagefilename");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${lienfichier}"));
        columnBinding.setColumnName("Lienfichier");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${lienimage}"));
        columnBinding.setColumnName("Lienimage");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${localisation}"));
        columnBinding.setColumnName("Localisation");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${resume}"));
        columnBinding.setColumnName("Resume");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                masterTableMouseClicked(evt);
            }
        });
        masterscrollpane.setViewportView(masterTable);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Choix des colonnes à afficher :");

        auteurC.setBackground(new java.awt.Color(255, 204, 102));
        auteurC.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        auteurC.setText("Dimension");
        auteurC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                auteurA(evt);
            }
        });

        raz.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        raz.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ceha/ressource/gomme.gif"))); // NOI18N

        idC.setBackground(new java.awt.Color(255, 204, 102));
        idC.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        idC.setText("Id");
        idC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idA(evt);
            }
        });

        sourceC.setBackground(new java.awt.Color(255, 204, 102));
        sourceC.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        sourceC.setText("source");
        sourceC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sourceA(evt);
            }
        });

        typedocC.setBackground(new java.awt.Color(255, 204, 102));
        typedocC.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        typedocC.setText("type document");
        typedocC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                typedocA(evt);
            }
        });

        jLabel2.setText("remise à zéro");

        javax.swing.GroupLayout donneesTablesJIFLayout = new javax.swing.GroupLayout(donneesTablesJIF.getContentPane());
        donneesTablesJIF.getContentPane().setLayout(donneesTablesJIFLayout);
        donneesTablesJIFLayout.setHorizontalGroup(
            donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(donneesTablesJIFLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(donneesTablesJIFLayout.createSequentialGroup()
                        .addGroup(donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(masterscrollpane, javax.swing.GroupLayout.DEFAULT_SIZE, 1018, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(donneesTablesJIFLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addGroup(donneesTablesJIFLayout.createSequentialGroup()
                                .addComponent(idC)
                                .addGap(18, 18, 18)
                                .addComponent(sourceC)
                                .addGap(15, 15, 15)
                                .addComponent(typedocC)
                                .addGap(337, 337, 337)
                                .addComponent(auteurC)
                                .addGap(205, 205, 205)
                                .addComponent(raz)))
                        .addGap(66, 66, 66))))
        );
        donneesTablesJIFLayout.setVerticalGroup(
            donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, donneesTablesJIFLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(donneesTablesJIFLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(donneesTablesJIFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(auteurC)
                            .addComponent(idC)
                            .addComponent(sourceC)
                            .addComponent(typedocC)))
                    .addComponent(raz, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addComponent(masterscrollpane, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        donneesTablesJIF.setBounds(20, 10, 950, 440);
        desktop.add(donneesTablesJIF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(desktop, javax.swing.GroupLayout.PREFERRED_SIZE, 981, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void masterTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_masterTableMouseClicked
        int id = masterTable.getSelectedRow();
        String filename = (String) masterTable.getValueAt(id, 1);
        System.out.println(filename);
        fiche.getVignette1().setIcon(new javax.swing.ImageIcon(filename));
        System.out.println(id);
        String lienfichier = (String) masterTable.getValueAt(id, 8);
//        lienfichierButton.setText(lienfichier);
}//GEN-LAST:event_masterTableMouseClicked

    private void auteurA(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_auteurA
        // TODO add your handling code here:
    }//GEN-LAST:event_auteurA

    private void idA(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idA
   
   TableColumn   column = masterTable.getColumnModel().getColumn(0);   
      column.setMaxWidth(0);
      column.setMinWidth(0);
    }//GEN-LAST:event_idA

    private void sourceA(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceA
        // TODO add your handling code here:
    }//GEN-LAST:event_sourceA

    private void typedocA(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typedocA
        // TODO add your handling code here:
    }//GEN-LAST:event_typedocA

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox auteurC;
    private javax.swing.JDesktopPane desktop;
    private javax.swing.JInternalFrame donneesTablesJIF;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JCheckBox idC;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private java.util.List<ceha.Fiche> list;
    private javax.swing.JTable masterTable;
    private javax.swing.JScrollPane masterscrollpane;
    private javax.persistence.Query query;
    private javax.swing.JButton raz;
    private javax.swing.JCheckBox sourceC;
    private javax.swing.JCheckBox typedocC;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
